home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Sept, 2000
- // Author: bb
- //
- // Procedure Name:
- // doGhost
- //
- // Description:
- // Enable or disable ghosting on the selected objects.
- //
- // Input Arguments:
- // $version: The version of this option box. Used to know how to
- // interpret the $args array.
- // "1" : first version of ghosts
- // "2" : second version of ghosts
- //
- // $args
- // Version 1
- // [0] $enable: enable or disable ghosts
- // Version 2
- // [0] $enable: enable or disable ghosts
- // [1] $ghostControl: ghostControl attribute value for ghosted objects
- // [2] $pre: ghostPreSteps attribute value for ghosted objects
- // [3] $post: ghostPostSteps attribute value for ghosted objects
- // [4] $stepSize: ghostFramesPerStep attribute value for ghosted objects
- // [5] $frames: ghostFrames attribute value for ghosted objects
- // [6] $start: ghostRangeStart attribute value for ghosted objects
- // [7] $end: ghostRangeEnd attribute value for ghosted objects
- // [8] $ghostDriver: the driver object whose keys are to ghost $obj
- //
- // Return Value:
- // none
- //
-
- proc string buildGhostSetAttrString(string $obj,
- int $enable,
- int $ghostControl,
- int $pre,
- int $post,
- int $stepSize,
- string $frames,
- float $start,
- float $end,
- string $ghostDriver)
- //
- // Description: Based on the argument values, build up a setAttr
- // command to control the specified ghosting attributes of the object.
- // $object: object to act on
- // $enable: enable or disable ghosting
- // $ghostControl: ghostControl attribute value for ghosted objects
- // Possible values are:
- // 0: global preferences
- // 1: custom frames
- // 2: custom frame pre/post
- // 3: custom key pre/post
- // 4: keyframe range
- // -1: do not modify ghost control or its associated attributes,
- // leave them as they are
- // $pre: ghostPreSteps attribute value for ghosted objects
- // $post: ghostPostSteps attribute value for ghosted objects
- // $stepSize: ghostFramesPerStep attribute value for ghosted objects
- // $frames: ghostFrames attribute value for ghosted objects
- // $start: ghostRangeStart attribute value for ghosted objects
- // $end: ghostRangeEnd attribute value for ghosted objects
- // $ghostDriver: the driver object whose keys are to ghost $obj
- //
- {
- string $setAttrCmds = ("setAttr "+$obj+".ghosting "+$enable+"; ");
- // Break the connection to ghostDriver attr
- string $srcAttrs[] = `listConnections -s true -d false -p true ($obj+".ghostDriver")`;
- if (size($srcAttrs) > 0) {
- $setAttrCmds += ("disconnectAttr " + $srcAttrs[0] + " " + $obj + ".ghostDriver; ");
- }
-
- if (0 == $enable || (-1 == $ghostControl)) {
- // the other ghosting attrs do not matter if we are not ghosting,
- // so return the command string now
- //
- return $setAttrCmds;
- }
-
- // type of ghosting control
- //
- $setAttrCmds += ("setAttr "+$obj+".ghostingControl "+$ghostControl+"; ");
-
- switch ($ghostControl) {
- case 0:
- {
- // global preferences, nothing to do here
- } break;
- case 1: {
- // custom frames
- $setAttrCmds += ("setAttr "+$obj+".ghostFrames -typ Int32Array ");
- $setAttrCmds += ($frames+"; ");
- } break;
- case 2:
- case 3: {
- // custom pre, post
- $setAttrCmds += ("setAttr "+$obj+".ghostPreSteps "+$pre+"; ");
- $setAttrCmds += ("setAttr "+$obj+".ghostPostSteps "+$post+"; ");
- $setAttrCmds += ("setAttr "+$obj+".ghostStepSize "+$stepSize+"; ");
- } break;
- case 4: {
- // keyframes
- $setAttrCmds += ("setAttr "+$obj+".ghostRangeStart "+$start+"; ");
- $setAttrCmds += ("setAttr "+$obj+".ghostRangeEnd "+$end+"; ");
- } break;
- }
-
- if ($ghostDriver != "")
- $setAttrCmds += ("connectAttr -f " + $ghostDriver + " " + $obj + ".ghostDriver");
-
- return $setAttrCmds;
- }
-
- proc int isTransform(string $obj)
- {
- string $isTransform[] = `ls -type transform $obj`;
- return size($isTransform);
- }
-
- proc int isJoint(string $obj)
- {
- string $type = `nodeType $obj`;
- return $type == "joint";
- }
-
- proc int isIntermediateObject(string $obj)
- {
- int $val = `getAttr ($obj+".intermediateObject")`;
- return $val == 1;
- }
-
- proc int ghostIt(string $object, int $enable,
- int $ghostControl,
- int $pre,
- int $post,
- int $stepSize,
- string $frames,
- float $start,
- float $end,
- int $hier,
- string $ghostDriver)
- //
- // Description: ghost or unghost an object
- // Args:
- // $object: object to act on
- // $enable: whether or not to ghost
- // $ghostControl: ghostControl attribute value for ghosted objects
- // $pre: ghostPreSteps attribute value for ghosted objects
- // $post: ghostPostSteps attribute value for ghosted objects
- // $stepSize: ghostStepSize attribute value for ghosted objects
- // $frames: ghostFrames attribute value for ghosted objects
- // $start: ghostRangeStart attribute value for ghosted objects
- // $end: ghostRangeEnd attribute value for ghosted objects
- // $hierarchy: whether to ghost the hierarchy below the selected object
- // $ghostDriver: the driver object whose keys are to ghost $object
- //
- {
- int $setGhost = 0;
- string $rels[];
- if($hier) {
- // include all the descedents
- $rels = `listRelatives -pa -ad $object`;
- } else {
- // Ghost children if $object is a transform
- if (isTransform($object) && !isJoint($object)) {
- $rels = `listRelatives -pa $object`;
- }
- }
- // include itself at the end of $rels[]
- $rels[size($rels)] = $object;
-
- for($rel in $rels) {
- // Ghost a node only if it's not a transform or if it's a joint
- if (!isTransform($rel) || isJoint($rel)) {
- if (!isIntermediateObject($rel)) {
- string $cmd = buildGhostSetAttrString(
- $rel, $enable, $ghostControl,
- $pre,$post,$stepSize,
- $frames, $start,$end,$ghostDriver);
- evalEcho $cmd;
- $setGhost += 1;
- }
- }
- }
- return $setGhost;
- }
-
- global proc
- doGhost( string $version, string $args[] )
- //
- // Description:
- // This procedure is used to enable or disable ghosts.
- // The arguments are implemented using a string array to
- // allow a variable number of arguments depending on the
- // version.
- // Arguments:
- // $version: the version
- // $args
- // Version 2
- // [0] $enable: enable or disable ghosts
- // [1] $hierarchy: whether to ghost the hierarchy below the selected object
- // [2] $ghostControl: ghostControl attribute value for ghosted objects
- // [3] $pre: ghostPreSteps attribute value for ghosted objects
- // [4] $post: ghostPostSteps attribute value for ghosted objects
- // [5] $stepSize: ghostStepSize attribute value for ghosted objects
- // [6] $frames: ghostFrames attribute value for ghosted objects
- // [7] $start: ghostRangeStart attribute value for ghosted objects
- // [8] $end: ghostRangeEnd attribute value for ghosted objects
- // [9] $useGhostDriver: whether to use first object's keys to ghost the rest objects
- //
- {
- int $counter = 0;
- int $enable = $args[0];
- int $ghostControl = -1; // leave ghost control as is
- int $pre = 0;
- int $post = 0;
- int $stepSize = 0;
- string $frames;
- float $start = 0;
- float $end = 0;
- int $hier = 0;
- int $useGhostDriver = 0;
- string $selection[] = `ls -sl`;
-
- int $versionNo = $version;
- if ($versionNo > 1) {
- $hier = $args[1];
- $ghostControl = $args[2];
- $pre = $args[3];
- $post = $args[4];
- $stepSize = $args[5];
- $frames = $args[6];
- $start = $args[7];
- $end = $args[8];
- $useGhostDriver = $args[9];
- }
-
- if ($useGhostDriver) {
- if ($enable) {
- if (size($selection) < 2) {
- error("Use Ghost Driver is on. Select a driver object, then driven objects.");
- return;
- }
- } else {
- if (size($selection) == 0) {
- error("Select objects to be unghosted.");
- return;
- }
- }
- } else {
- if (size($selection) == 0) {
- if ($enable) {
- error("Select objects to be ghosted.");
- } else {
- error("Select objects to be unghosted.");
- }
- return;
- }
- }
-
- int $i = 0;
- string $ghostDriver;
- if ($useGhostDriver && $enable) {
- $ghostDriver = $selection[0] + ".message";
- $i = 1;
- }
-
- int $numObj = `size $selection`;
- for( ; $i < $numObj; $i++) {
- string $sel = $selection[$i];
- $counter += ghostIt( $sel,
- $enable,
- $ghostControl,
- $pre,$post,$stepSize,
- $frames,
- $start,
- $end,
- $hier,
- $ghostDriver);
- }
-
- if ($counter == 0 && $enable) {
- error("Objects selected could not be ghosted.");
- }
- }
-